const express = require('express');
const axios = require('axios');
const bodyParser = require('body-parser');
const cors = require('cors');


const app = express();
app.use(cors())


app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));

app.post('/openai', (req, res) => {
    // console.log(req.body.question);
    //向openai转发请求
    axios.post('https://service-3zopgrzw-1319127165.usw.apigw.tencentcs.com/v1/chat/completions', {
        model: 'gpt-3.5-turbo',
        messages: [{ role: 'user', content: req.body.question }],
        temperature: 0.7
    },
        {
            headers: {
                'Content-Type': 'application/json',
                Authorization: 'Bearer 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'
            }
        }).then(response => {
            res.end(JSON.stringify(response.data.choices))
            // console.log(JSON.stringify(response.data.choices));
        })

})


app.listen(3000, () => {
    console.log('listen on port 3000');
})